package org.zpmis.domain.role.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.zpmis.domain.role.model.SysPermission;

import javax.persistence.*;
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
public class SysPermissionListVo implements Serializable {
    /**
     * 主键id
     */
    private Long id;

    /**
     * api url
     */
    private String apiUrl;

    /**
     * 权限code
     */
    private String permissionCode;

    /**
     * 权限名
     */
    private String permissionName;
    /**
     * 权限分组
     */
    private String permissionGroup;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 修改时间
     */
    private String updateTime;

    /**
     * 创建人
     */
    private Long createUser;

    /**
     * 修改人
     */
    private Long updateUser;

    public SysPermissionListVo(SysPermission sysPermission) {
        this.id = sysPermission.getId();
        this.apiUrl = sysPermission.getApiUrl();
        this.permissionCode = sysPermission.getPermissionCode();
        this.permissionName = sysPermission.getPermissionName();
        this.createTime = sysPermission.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(sysPermission.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.updateTime = sysPermission.getUpdateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(sysPermission.getUpdateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.createUser = sysPermission.getCreateUser();
        this.updateUser = sysPermission.getUpdateUser();
        this.permissionGroup = sysPermission.getPermissionGroup();
    }
}